import { locations } from "../../../gpu/locations";
const PointShadowVertex =/*wgsl*/`
/**
 *灯光投影下的顶点着色器
 * @class
 *  
 */
 struct Trans {
  modelMat:mat4x4<f32>,    
  normalMat:mat4x4<f32>,      
};
 struct PointShadow {
  lightPos:vec3<f32>,    
  far:f32,   
  singleLightCameras:array<mat4x4<f32>>    
};
#if ~{def.trans}
@group(${locations.trans[0]}) @binding(${locations.trans[1]}) var<uniform> trans : Trans;
#endif
#if ~{def.transinstance}
@group(${locations.transinstance[0]}) @binding(${locations.transinstance[1]})  var<storage,read> trans:array<Trans>;
#endif
@group(${locations.SingleLightCamera[0]}) @binding(${locations.SingleLightCamera[1]}) var<storage,read> pointShadow :PointShadow;
@group(${locations.ShadowPointIndex[0]}) @binding(${locations.ShadowPointIndex[1]}) var<uniform> shadowPointIndex :u32;

struct Input {
  @builtin(instance_index) index : u32,
  @location(${locations.position[1]}) position : vec3<f32>,
};
struct Output {
  @builtin(position) Position : vec4<f32>,
  @location(0) worldPosition:vec4<f32>,
};
@vertex
fn main(input:Input) -> Output {
  var modelMatrix:mat4x4<f32>;
  // 从trans中分解处模型矩阵与法向量矩阵
  #if ~{def.trans}
  modelMatrix=trans.modelMat;
  #endif
  #if ~{def.transinstance}
  modelMatrix=trans[input.index].modelMat;
  #endif
  var output : Output;
  var worldPosition=  modelMatrix *vec4(input.position, 1.0);
  var worldPosition1=worldPosition.xyz/worldPosition.w;
  var singleLightCamera=pointShadow.singleLightCameras[shadowPointIndex];
  var clipPosition= singleLightCamera *worldPosition;
  output.Position=clipPosition;
  output.worldPosition= vec4(worldPosition1,1.0);
  return output;
}
`
export { PointShadowVertex }
